/*@@

    Copyright (c) 2010 BlueSky LTD.  All rights reserved. 

    Created_datetime : 2010-7-28 15:23:32

    File Name :	base_stlex.h

    Author : Wang Hu (ghoststears@gmail.com)

    Description : 

@@*/

#ifndef __BASE_STLEX_H__
#define __BASE_STLEX_H__

#include <algorithm>

namespace BLK {
    template<typename T>
    void DeleteVectorEntry(T& v)
    {
        typedef typename T::iterator iterator_t;
        for (iterator_t it = v.begin(); it != v.end(); ++it)
        {
            delete *it;
        }
        
        v.clear();
    }

    template<typename T>
    void VectorExtend(T& v, const T& ev)
    {
        typedef typename T::const_iterator const_iterator_t;
        for (const_iterator_t it = ev.begin(); it != ev.end(); ++it)
        {
            v.push_back(*it);
        }
    }

    template<typename T>
    void DeleteEntry(const T& m)
    {
        delete m.second;
    }
    
    template<typename T>
    void DeleteMapEntry(const T& m)
    {
        std::for_each(m.begin(), m.end(), DeleteEntry<typename T::value_type>);
    }
};

#endif /* __BASE_STLEX_H__ */
